/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasi?                                      *
 *   ivasic@gmail.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>

#include "ui_uimainwindow.h"
#include "logobserver.h"

class QMenu;
class QAction;
class QToolbar;

class LogWidget;
class MenuWidget;
class CentralView;

class MainWindow : public QMainWindow, private Ui::MainWindow
{
		Q_OBJECT

	public:
		MainWindow(QWidget* parent = 0, Qt::WFlags fl = 0);
		~MainWindow();
		
	public slots:
		void showNewUserDialog();
		void showNewTorrentDialog();
		void showAboutDialog();
		void onSidebarItemActivated(int item);
		
		///Prikazuje settings dialog
		void showSettingsDialog();

	private slots:
		void iconActivated(QSystemTrayIcon::ActivationReason reason);

	private:
		/**
		 * @brief Kreira ikonicu u system tray.
		 * Kreira m_systray, kreira m_systrayMenu i postavlja actions za oba objekta.
		 */
		void createSystemTrayIcon();
		
		/**
		 * @brief Kreira sve QActions za ovaj objekat.
		 */
		void createActions();
		
		/**
		 * @brief Postavlja sve signal-slot konekcije.
		 */
		void setupConnections();
		
		/**
		 * @brief Kreira i podešava sve Dock widgete.
		 */
		void setupWidgets();
		
		/**
		 * @brief Podešava meni.
		 * Ovde podesiti sve stavke koje treba da se pojave u meniju.
		 */
		void setupMenu();
		
		/**
		 * @brief Podešava toolbar.
		 * Ovde podesiti sve stavke koje treba da se pojave u toolbaru.
		 */
		void setupToolbar();
		
		/**
		 * @brief Podešava menu sidebar.
		 * Ovde podesiti sve stavke koje treba da se nadju u sidebar-u.
		 */
		void setupSidebar();
		
		/**
		 * @brief Pamti stanje prozora.
		 * Upisuje u settings izgled prozora u trenutku pozivanja ove fje
		 * i posle se može vratiti takvo stanje pozivom restoreUIState()
		 */
		void saveUIState();
		
		/**
		 * @brief Vraća stanje prozora.
		 * Čita iz settingsa poslednji ubeleženi izgled prozora 
		 * i vraća takvo stanje
		 * @see saveUIState()
		 */
		void restoreUIState();

	private:
		QSystemTrayIcon* m_systray;
		QMenu* m_systrayMenu;
		
		//Toolbar
		QToolBar* m_toolbar;

		//actions
		QAction *minimizeAction;
		QAction *maximizeAction;
		QAction *restoreAction;
		QAction *quitAction;
		QAction *newUserAction;
		QAction *newTorrentAction;
		QAction *showAbout;
		QAction *showSettings;
		
		//Widgets
		LogWidget* m_logWidget;
		MenuWidget* m_menuWidget;
		CentralView* m_view;
};

#endif

